
=begin rdoc
关于博客的分类名的基本操作。
=end
class Manager::Blog::SortsController < Admin::WmsApplicationController
  before_action :set_post, only: [:destroy, :edit]
  before_action :authenticate_user! , except: [:index]
  load_and_authorize_resource :blog_sort

  def initialize
    super
  end

  # /manager/blog/sorts GET
  def index
    @blog_sorts = BlogSort.all
    @blog_sort = BlogSort.new
  end

  def new
  end
  # /manager/blog/sorts POST
  def create
    @blog_sort = BlogSort.new(create_params)

    @blog_sort.with_lock do    #悲观锁的变形版本。
      respond_to do |format|
         @blog_sort.admin_user=current_user

        if @blog_sort.save

          format.json {render @blog_sort.to_json, status: :created, location: @blog_sort}
          format.js
        else
          format.html { redirect_to action: :index, notice: 'sorrt,添加失败。'}
        end
      end

    end

  end

  def edit
  end
  # /manager/blog/sorts/1 DELETE
  def destroy

    _destroy_blog_sort = @blog_sort.destroy
      response do |format|
        #默认情况下只是清空外键的引用
        if _destroy_blog_sort
          format.js
        else
          format.html { redirect_to action: :index, notice: '删除失败！' }
        end
      end


  end



  private
  def set_post
    @blog_sort = BlogSort.find(params[:id])
  end

  def post_params
    params.require(:post).permit(:sort_name)
  end
  def create_params
    params.require(:blog_sort).permit(:sort_name)
  end
end
